import { Transferable } from './interfaces';
import { GameObject, GameObjectOptions } from './gameObject';
import { createEmptyTranformMatrix, matrixMultiply } from '../utils';

export interface TGameObjectOptions extends GameObjectOptions {
  width: number;
  height: number;
  rotate?: number;
  scale?: {
    x: number,
    y: number,
  };
  skew?: {
    x: number,
    y: number,
  };
  origin?: {
    x: number,
    y: number,
  };
}

/** transferable game object */
export abstract class TGameObject extends GameObject implements Transferable {
  width: number;

  height: number;

  rotate = 0;

  scale = { x: 1, y: 1, };

  get scaleX () { return this.scale.x; }
  set scaleX (x: number) { this.scale.x = x; }

  get scaleY () { return this.scale.y; }
  set scaleY (y: number) { this.scale.y = y; }

  skew = { x: 0, y: 0, };

  get skewX () { return this.skew.x; }
  set skewX (x: number) { this.skew.x = x; }

  get skewY () { return this.skew.y; }
  set skewY (y: number) { this.skew.y = y; }

  origin = { x: 0, y: 0, };

  get originX () { return this.origin.x; }
  set originX (x: number) { this.origin.x = x; }

  get originY () { return this.origin.y; }
  set originY (y: number) { this.origin.y = y; }

  get position () { return { x: this.x, y: this.y, } }
  set position (obj: {x: number, y: number}) { this.x = obj.x; this.y = obj.y; }

  transformMatrix: number[][];

  constructor (options: TGameObjectOptions) {
    super(options);

    const { width, height, rotate = 0, scale, skew, origin, } = options;
    this.width = width;
    this.height = height;
    this.rotate = rotate;
    scale && (this.scale = scale);
    skew && (this.skew = skew);
    origin && (this.origin = origin);
  }
}
